/*
 * 退货记录表格配置
 * 定义表格列、表单字段、查询条件等
 */
export default function () {
    return {
        // 表格配置
        table: {
            key: 'id',
            cnName: '退货记录',
            name: 'return_order',
            url: '/api/return_order/',
            sortName: 'create_time', // 默认排序字段
            sortDirection: 'desc'     // 降序排列
        },
        
        // 表格列定义
        columns: [
            {
                field: 'id',
                title: 'ID',
                type: 'int',
                width: 80,
                readonly: true,
                hidden: true // 隐藏ID列
            },
            {
                field: 'return_no',
                title: '退货编号',
                type: 'string',
                width: 180,
                readonly: true,
                require: true,
                align: 'left',
                sort: true
            },
            {
                field: 'order_no',
                title: '订单编号',
                type: 'string',
                width: 180,
                readonly: true,
                align: 'left'
            },
            {
                field: 'return_name',
                title: '商品名称',
                type: 'string',
                width: 200,
                readonly: true,
                require: true
            },
            {
                field: 'customer_id',
                title: '客户ID',
                type: 'int',
                width: 100,
                readonly: true
            },
            {
                field: 'create_time',
                title: '创建时间',
                type: 'datetime',
                width: 160,
                readonly: true,
                require: true,
                sort: true,
                formatter: (row, column, cellValue) => {
                    if (!cellValue) return '';
                    const date = new Date(cellValue);
                    return date.toLocaleString('zh-CN', {
                        year: 'numeric',
                        month: '2-digit',
                        day: '2-digit',
                        hour: '2-digit',
                        minute: '2-digit',
                        second: '2-digit'
                    });
                }
            },
            {
                field: 'total_amount',
                title: '订单金额',
                type: 'decimal',
                width: 120,
                readonly: true,
                summary: true, // 显示合计
                formatter: (row, column, cellValue) => {
                    return cellValue ? `¥${cellValue.toFixed(2)}` : '¥0.00';
                }
            },
            {
                field: 'quantity',
                title: '数量',
                type: 'int',
                width: 100,
                readonly: true,
                summary: true
            },
            {
                field: 'order_status',
                title: '状态',
                type: 'byte',
                width: 120,
                bind: {
                    key: 'return_order_status',
                    data: []
                },
                formatter: (row, column, cellValue) => {
                    const statusMap = {
                        0: { text: '待处理', type: 'warning' },
                        1: { text: '已审核', type: 'primary' },
                        2: { text: '已完成', type: 'success' },
                        3: { text: '已取消', type: 'info' }
                    };
                    const status = statusMap[cellValue] || { text: '未知', type: 'info' };
                    return `<span class="el-tag el-tag--${status.type} el-tag--small">${status.text}</span>`;
                }
            },
            {
                field: 'shipping_address',
                title: '退货说明',
                type: 'string',
                width: 300,
                readonly: true
            },
            {
                field: 'Creator',
                title: '创建人',
                type: 'string',
                width: 100,
                readonly: true
            }
        ],
        
        // 查询表单字段
        searchFormFields: [
            {
                field: 'return_no',
                title: '退货编号',
                type: 'string',
                placeholder: '请输入退货编号'
            },
            {
                field: 'return_name',
                title: '商品名称',
                type: 'string',
                placeholder: '请输入商品名称'
            },
            {
                field: 'order_status',
                title: '退货状态',
                type: 'select',
                data: [
                    { key: 0, value: '待处理' },
                    { key: 1, value: '已审核' },
                    { key: 2, value: '已完成' },
                    { key: 3, value: '已取消' }
                ]
            },
            {
                field: 'create_time',
                title: '创建时间',
                type: 'daterange',
                placeholder: ['开始日期', '结束日期']
            }
        ],
        
        // 查询表单配置
        searchFormOptions: {
            width: 200,
            labelWidth: 90
        },
        
        // 编辑表单字段（只读模式）
        editFormFields: [
            {
                field: 'return_no',
                title: '退货编号',
                type: 'string',
                readonly: true,
                require: true
            },
            {
                field: 'return_name',
                title: '商品名称',
                type: 'string',
                readonly: true,
                require: true
            },
            {
                field: 'customer_id',
                title: '客户ID',
                type: 'int',
                readonly: true
            },
            {
                field: 'order_status',
                title: '退货状态',
                type: 'select',
                data: [
                    { key: 0, value: '待处理' },
                    { key: 1, value: '已审核' },
                    { key: 2, value: '已完成' },
                    { key: 3, value: '已取消' }
                ],
                require: true
            },
            {
                field: 'total_amount',
                title: '退货金额',
                type: 'decimal',
                readonly: true
            },
            {
                field: 'shipping_address',
                title: '退货说明',
                type: 'textarea',
                readonly: true
            },
            {
                field: 'create_time',
                title: '创建时间',
                type: 'datetime',
                readonly: true
            }
        ],
        
        // 编辑表单配置
        editFormOptions: {
            width: '60%',
            labelWidth: 120,
            title: '退货记录详情'
        },
        
        // 明细表配置（暂时为空）
        detail: {},
        details: []
    }
}

